home *** CD-ROM | disk | FTP | other *** search
- /*
- ** $VER: RunCommand.br 1.3 (28.8.95)
- **
- ** Intended for use as an SortMail external script, but can be used from the
- ** Shell as well. Also servers as an example of how to create external
- ** scripts for SortMail.
- **
- ** See SortMail.guide for documentation
- **
- */
-
- /*
- ** INITIALIZATION
- */
-
- options results
-
- signal on syntax
- signal on break_c
- signal on halt
-
- options failat 30
-
- parse arg arguments /* Get command line arguments */
-
- template = 'COMMAND/A,OPTIONS/K,ASYNC/S' /* READARGS template */
-
- /*
- ** See if I'm run from Thor. If true, fromthor = 1 and thorport is Thor's
- ** ARexx port, otherwise fromthor = 0
- */
-
- thorport = getclip('SM_ThorPort')
- if thorport ~= '' then do
- fromthor = 1
- end
- else fromthor = 0
-
- /*
- ** Check if BBSREAD's ARexx port is open, open it if it's not
- */
-
- if ~show('P', 'BBSREAD') then do
- address(command)
- 'Run >NIL: `GetEnv THOR/THORPath`bin/LoadBBSRead'
- 'WaitForPort BBSREAD'
- if rc ~= 0 then do
- say 'Couldn''t open BBSREAD''s ARexx port.'
- exit(20)
- end
- end
-
- /*
- ** Parse command line
- */
-
- args.ASYNC = 0 /* Switches are set to 0 so if tests can
- be performed on them, like below */
- address(bbsread)
- 'READARGS 'template args' CMDLINE 'arguments
- if rc ~= 0 then do
- say 'READARGS failed: 'BBSREAD.LASTERROR
- exit(rc)
- end
-
- /*
- ** MAIN CODE - substitute with your own
- */
-
- /*
- ** Create the command line
- */
-
- if args.ASYNC then
- cmdline = 'Run >NIL: "' || args.COMMAND || '" >T:RunCommand.out'
- else
- cmdline = '"' || args.COMMAND || '" >T:RunCommand.out'
-
- if symbol('args.OPTIONS') = 'VAR' then
- cmdline = cmdline || ' ' || args.OPTIONS
-
- /*
- ** Execute the command line
- */
-
- address command cmdline
-
- if rc ~= 0 then do
- commandrc = rc
- erropen = open(ef, 'T:RunCommand.out', 'R')
- if erropen then do
- say 'External script RunCommand.br failed: 'readln(ef)
- call close(ef)
- if exists('T:RunCommand.result') then
- address command 'Delete "T:RunCommand.out" QUIET'
- end
- else
- say 'External script RunCommand.br failed: Unknown error'
- exit(commandrc)
- end
-
- /*
- ** Skip to cleanup: to do a clean exit
- */
-
- signal cleanup
-
-
- /*
- ** ERROR HANDLING AND EXITING
- */
-
- /*
- ** Error handling routine
- */
-
- error:
- syntax:
-
- /*
- ** Show BBSREAD, THOR or ARexx error
- */
-
- select
- when symbol('BBSREAD.LASTERROR') = 'VAR' then
- say 'BBSREAD returned 'rc' in line 'sigl': 'BBSREAD.LASTERROR
-
- when symbol('THOR.LASTERROR') = 'VAR' then
- say 'THOR returned 'rc' in line 'sigl': 'THOR.LASTERROR
-
- otherwise say 'Error 'rc' in line 'sigl': 'errortext(rc)
- end
-
- /*
- ** Leave script, returning the proper error code (if any)
- */
-
- cleanup:
- break_c:
- halt:
-
- if symbol('rc') = 'VAR' then exit(rc)
- else exit(0)
-